from pydantic import Field, ConfigDict
from typing_extensions import Self

from app.utils.decorators.optional import optional
from ..models.base import SQLBaseModel, IdType
from ..models.menu import BaseMenu


class MenuCreate(BaseMenu):
    parent_id: IdType | None = Field(description="父级ID")


@optional(without_fields=["id"])
class MenuUpdate(MenuCreate):
    id: IdType


class MenuOut(SQLBaseModel, BaseMenu):
    model_config = ConfigDict(from_attributes=True)
    parent_id: IdType | None = Field(description="父级ID")


class MenuTreeOut(SQLBaseModel, BaseMenu):
    model_config = ConfigDict(from_attributes=True)

    parent_id: IdType | None = Field(description="父级ID")
    children: list[Self] | None= Field(default_factory=list)

class MenuExport(MenuOut):
    model_config = ConfigDict(from_attributes=True)
